package org.shilong.UI.party;

import org.shilong.UI.R;
import org.shilong.Utility.IntentUtility;
import org.shilong.Utility.Loader.PartyListViewLoader;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;

/**
 * 我的聚会功能模块
 * @author cesc
 *
 */
public class BrandNewMyPariesFrame extends Activity implements OnClickListener{

	private Button toAddPageButton;

	private ListView show_my_parties_listview;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

		setContentView( R.layout.new_layout_show_my_party_content );

		listenBroadcast();

		initViews();

		registerEvents();


	}

	void listenBroadcast(){

		IntentFilter filter = new IntentFilter( BrandPartyCenterFrame.ACTION_REFRESH_MY_PAREIS_DATAS );

		registerReceiver(new RefreshDatasListener(), filter );

	}

	void initViews(){

		show_my_parties_listview = ( ListView )this.findViewById( R.id.show_my_parties_listview );

		toAddPageButton = (Button)this.findViewById( R.id.to_create_my_party_button );

		PartyListViewLoader loader = new PartyListViewLoader(show_my_parties_listview, PartyListViewLoader.MY_PARTY, this );
		loader.startTask();
	}


	void registerEvents(){

		toAddPageButton.setOnClickListener( this );

	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch ( v.getId()) {
		case R.id.to_create_my_party_button:

			toAddNewPartyLogic();

			break;

		default:
			break;
		}
	}

	public void toAddNewPartyLogic(){


		System.out.println("=========>跳转到新建聚会<============");
		IntentUtility.goNextFrame( this, AddNewPartyFrame.class , null );

	}



	private class RefreshDatasListener extends BroadcastReceiver{

		@Override
		public void onReceive(Context content, Intent intent ) {
			// TODO Auto-generated method stub

			System.out.println("启动获取我的聚会功能...");

			PartyListViewLoader loader = new PartyListViewLoader(show_my_parties_listview, PartyListViewLoader.MY_PARTY, BrandNewMyPariesFrame.this );

			loader.startTask();

		}}
}
